package com.tj.tj_java.mapper;

import com.tj.tj_java.dto.UserCredentialsDto;
import com.tj.tj_java.pojo.User;
import org.apache.ibatis.annotations.*;
//第二步 mapper层也叫dao层  操作数据库
@Mapper
public  interface UserMapper {
//@select查询 @Insert 新增 @Delete 删除 @update更新数据

    //通过 邮箱 查询 用户
    @Select("select * from users where email = #{email};")
    User getUserByEmail(String email);

    //通过 邮箱 查询 用户id
    @Select("select userId from users where email = #{email};")
    int getUserIdByEmail(String email);

    //通过 用户名 查询 用户
    @Select("select * from users where name = #{name}")
    User getUserByName(String name);

    //注册
    @Insert("insert into users(name,password,email) values (#{name},#{password},#{email})")
    void addUser(UserCredentialsDto user);

    //修改密码
    @Update("update users set password=#{newPassword} where userId=#{userId}")
    void updatePassword(String newPassword, int userId);

}


